import {
  registerMicroApps, RegistrableApp, // 注册子应用
  runAfterFirstMounted, // 当地一个子应用装载完毕
  // setDefaultMountApp, // 设置默认装载的子应用
  start
} from "qiankun";

import micAppConfig from "./config";
import { ApiSysEventBus } from "./eventBus/apiSys";
import initGlobalStore from "./initGlobalStore";
import { MicAppProps } from "./micappProps";
import windowState from "./windowState";

const micApplist:Array<RegistrableApp<any>>=micAppConfig.childAppList.map(item=>{
  let result:RegistrableApp<any>={
    name: item.name,
    entry: item.entry,
    container: "#childapp",
    activeRule: `${micAppConfig.prefixRoute}${
      micAppConfig.prefixRoute && micAppConfig.prefixRoute != "" ? "/" : ""
    }${micAppConfig.childAppNode}${
      micAppConfig.childAppNode && micAppConfig.childAppNode != "" ? "/" : ""
    }${item.name}`,
    props: new MicAppProps()
  }
  return result 
})

export default () => {
  registerMicroApps(micApplist);
  initGlobalStore();
  window.$micAppWindowState = windowState;

  // // 以上代码放在设置默认app之前即可
  // // setDefaultMountApp("home");

  // // 第一个子应用加载完毕后回调
  runAfterFirstMounted(() => {
    console.log("第一个子应用加载完毕后的回调");
  });

  // start(); 启动位置视情况变更
  // if (!window.$qiankunStarted) {
  //     console.log("乾坤开始")
  //     window.$qiankunStarted = true;
  //     start({
  //       sandbox: true,
  //     });
  //   }
};
